package com.tenqian.media.controller;

import com.tenqian.Result;
import com.tenqian.enums.ResultEnum;
import com.tenqian.media.service.MediaService;
import com.tenqian.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class MediaController {
    Logger logger = LoggerFactory.getLogger(MediaController.class);
    @Autowired
    MediaService mediaService;

    @RequestMapping("/video/search/{q}")
    @ResponseBody
    public Result search(@PathVariable("q") String q) {
        try {
            return mediaService.video_search(q);
        } catch (Exception e) {
            logger.error("搜索视频失败", e);
            return ResultUtil.error(ResultEnum.UNKONW_ERROR);
        }
    }

    @RequestMapping("/news/get")
    @ResponseBody
    public Result getNews(@RequestParam("page") String page, @RequestParam("size") String size) {
        try {
            return mediaService.news_get(page, size, "头条");
        } catch (Exception e) {
            logger.error("新闻搜索失败", e);
            return ResultUtil.error(ResultEnum.UNKONW_ERROR);
        }
    }

    @RequestMapping("/hottestVideo")
    @ResponseBody
    public Result getHottestVideo(@RequestParam("page") int page)

    {
        try {
            return mediaService.hottestVideo(page);
        } catch (Exception e) {
            logger.error("获取最热视频失败", e);
            return ResultUtil.error(ResultEnum.UNKONW_ERROR);
        }
    }
}
